This topic provides information for generating and training deep models for semantic segmentation. In many cases, Deep Learning has surpassed other approaches, such as thresholding, K-means clustering, classic machine learning, and others, for semantic segmentation. Semantic segmentation is the task of classifying each pixel in an image from a predefined set of classes that are “semantically interpretable” and correspond to real-world categories. This is also known as dense prediction because it predicts the meaning of each pixel.
The following video provides an overview of image segmentation with Deep Learning. Other videos in this section describe case studies about training deep models for different segmentation challenges.
The video below provides an overview of training deep models for segmenting image data.
Image Segmentation with Deep Learning (43:05)
You also view this video and others in the Getting Started with Deep Learning section on our website (www.theobjects.com/dragonfly/deep-learning-getting-started.html).
The following topics are discussed in the video. Links to Help topics and other sources with further information are also provided.
The video below provides a case study for segmenting fabric fibers with Deep Learning.
Training a Deep Model for Segmenting Fabric Fibers (23:16)
You also view this video and others in the Deep Learning Case Studies section on our website (www.theobjects.com/dragonfly/deep-learning-case-studies.html).
The video below provides a case study for segmenting the multiple material phases.
KitKat Segmentation Case Study (11:44):
You also view this video and others in the Deep Learning Case Studies section on our website (www.theobjects.com/dragonfly/deep-learning-case-studies.html).
The following items are required for training a deep model for semantic segmentation:
Note A selection of untrained models suitable for binary and multi-class segmentation are supplied with the Deep Learning Tool (see Deep Learning Architectures). You can also download models from the Infinite Toolbox (see Infinite Toolbox), or import models from Keras.
The following items are optional for training a deep model for semantic segmentation:
Multi-ROIs that are used as the target output for semantic segmentation must meet the following conditions:
Note Applying a mask may limit the number of input patches that are processed (see Applying Masks).
As shown in the illustration below, three distinct material phases in a training dataset were labeled as separate classes. You should note that labeling can be done directly on a multi-ROI as of Dragonfly version 2020.1 (see Multi-ROI Classes and Labels). You can also choose to work on multiple regions of interest, from which you can create a multi-ROI (see Creating Multi-ROIs from Regions of Interest).
Multi-class labeling
To help monitor and evaluate the progress of training Deep Learning models, you can designate a 2D rectangular region for visual feedback. With the Visual Feedback option selected, the model’s inference will be displayed in the Training dialog in real time as each epoch is completed, as shown on the right of the screen capture below. In addition, you can create a checkpoint cache so that you can save a copy of the model at a selected checkpoint (see Enabling Checkpoint Caches and Loading and Saving Model Checkpoints). Saved checkpoints are marked in bold on the plotted graph, as shown below.
Training dialog
With the Rectangle tool that is available on the Annotate panel, add a 2D rectangular region that includes the area or features you want to monitor during training.
Note Any region that you define for visual feedback should not contain labeled voxels.

Note The visual feedback image for each epoch is saved during model training. You can review the result of each epoch by scrolling through the plotted graph. If the checkpoint cache is enabled, you can also save the model at a selected checkpoint when you review the training results (see Loading and Saving Model Checkpoints).
Dragonfly's Deep Learning Tool provides a number of deep models — including U-Net, DeepLabV3+, FC-DenseNet, and others — that are suitable for binary and multi-class semantic segmentation. Semantic segmentation is the process of associating the voxels of an image with a class label.
The Deep Learning Tool dialog appears.
The Model Generator dialog appears (see Model Generator for additional information about the dialog).
This will filter the available architectures to those recommended for segmentation.

Note A description of each architecture is available in the Architecture Description box, along with a link for more detailed information (see also ).
Recommendation U-Net models are often the easiest to train and produce good results in many cases. For a more powerful option, you might consider Sensor3D, which uses a 3D context.

For example, if your training set multi-ROI has four classes, then you must enter a Class Count of 4. If you are training a model for binary segmentation, your multi-ROI would have two classes and you must enter a Class Count of 2.

Note If required, you can edit the input names.

Note An initial set of training parameters, which should work well in most cases, are provided with the semantic segmentation models supplied with the Deep Learning Tool. You should also note that training parameters are saved with each model and can be reused for future training.
After processing is complete, a confirmation message appears at the bottom of the dialog.
Information about the loaded model appears in the dialog (see Details), while a graph view of the data flow is available on the Model Editing panel (see Model Editing Panel).
You can start training a supported model for semantic segmentation after you have prepared your training input(s) and output(s), as well as any required masks (see Prerequisites).
To open the Deep Learning Tool, choose Artificial Intelligence > Deep Learning Tool on the menu bar.
General information about the model appears in the Details box, while the Classes box lists the number of classes selected for the model (see Model Overview Panel).
Note You can edit the color and name assigned to each class. You should also note that the data flow through the model is shown on the Model Editing panel show.
Note In most cases, you should be able to train a semantic segmentation model supplied with the Deep Learning Tool as is, without making changes to its architecture.
The Model Training panel appears (see Model Training Panel).
Note If you chose to train your model in 3D, then additional options will appear for the input, as shown below. See Configuring Multi-Slice Inputs for information about selecting reference slices and spacing values.

Note If your model requires multiple inputs, select the additional input(s), as required.

Note Only multi-ROIs with the number of classes corresponding to model's class count and the geometry of the input dataset(s) will be available in the menu.
The completed Training Data should look something like this:

Note If you are training with multiple training sets, click the Add New
button and then choose the required input(s), output, and mask for the additional item(s).

See Basic Settings for information about choosing an input (patch) size, epochs number, loss function, optimization algorithm, and so on.

Note You should monitor the estimated memory ratio when you choose the training parameter settings. The ratio should not exceed 1.00 (see Estimated Memory Ratio).
You should note that this step is optional and that these settings can be adjusted after you have evaluated the initial training results.
You can monitor the progress of training on the training Model dialog, as shown below.
Recommendation During training, the default =quantities 'loss' and 'val_loss' should decrease. You should continue to train until 'val_loss' stops decreasing. If required, you can increase the number of significant digits to make sure that small changes to monitored quantities can be noted (see Selecting the Views Preferences).
When training is complete or is stopped, the Training Results dialog appears.
You can also generate previews of the original data or test set to further evaluate the model (see Previewing Training Results).
Note If your results continue to be unsatisfactory, you might consider changing the selected model architecture.
You can also process datasets in the Segment with AI panel (see Segment with AI).
After training is complete or stopped, you can evaluate the results in the Training dialog, as well as generate previews of a test set or the original data to evaluate the predictive model (see Previewing Training Results).
You can view the results on the Graph tab, shown below, on which epochs and the selected metrics are plotted on a graph. In addition, the inference within a selected 2D region is shown for each epoch if a region for visual feedback was selected as a training input.
Training results (Graph view)
You can do the following in the Training dialog on the Graph tab:
You can also view the results on the List tab, on which the learning rate and other metrics are shown in a table view for each epoch.
Training results (List view)
The results for the total training can be exported in the comma-separated values (*.CSV extension) file format.